package com.nlelpct.manage.controller;

import com.nlelpct.manage.model.vo.MenuVo;
import com.nlelpct.manage.model.vo.MyCurrentMenuVo;
import com.nlelpct.manage.model.vo.ResponseResult;
import com.nlelpct.manage.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author :小马
 * @date : 2023-10-12
 */
@RestController
@RequestMapping("menu")
public class MenuController {

    private final ISysMenuService sysMenuService;

    @Autowired
    public MenuController(ISysMenuService sysMenuService) {
        this.sysMenuService = sysMenuService;
    }

    /**
     * 获取当前系统的菜单权限树
     */
    @PreAuthorize("hasRole('admin')")
    @GetMapping("/getMenuStructure")
    public ResponseResult<List<MenuVo>> getMenuStructure() {
        return sysMenuService.getMenuStructure();
    }

    /**
     * 获取当前登录用户的菜单权限树
     */
    @PreAuthorize("hasRole('admin')")
    @GetMapping("/getOwnedMenu")
    public ResponseResult<MyCurrentMenuVo> getOwnedMenu() {
        return sysMenuService.getOwnedMenu();
    }
}
